package jwr.ex2;

import java.util.InputMismatchException;
import java.util.Scanner;

public class ReserveMain {

	public static void main(String[] args) {
		Scanner sc;
		final String MSG1 = "예약(1), 조회(2), 취소(3), 끝내기(4) >>";
		final String MSG2 = "좌석 구분 S<1>, A<2>, B<3> >>";
		final String NAME = "이름 >>";
		final String NUM = "번호 >>";
		
		Reserve rs = new Reserve();
		while(true){
			sc = new Scanner(System.in);
			try{
				System.out.print(MSG1);
				switch(sc.nextInt()){
					case 1:	
						System.out.print(MSG2);
						rs.setRating(sc.nextInt());
						 getSeatRating(rs);
						 if(rs.getRating()>=1 && rs.getRating()<4){
						  System.out.print(NAME);
							 rs.setName(sc.next());
							 System.out.print(NUM);
							 rs.setNum(sc.nextInt());
							if(rs.compare()){
								 rs.newReserve(rs);
							 }else{
								 System.out.println("이미 예약되어있습니다.");
							}
						}else {
							System.out.println("S, A, B 석중 골라주세요.");
						} // if
						break;
					case 2: 
						System.out.println(rs.readReserve());
						break;
					case 3:
						System.out.print(MSG2);
						rs.setRating(sc.nextInt());
						getSeatRating(rs);
						System.out.print(NAME);
						rs.setName(sc.next());
						rs.removeReserve();
						break;
					case 4: 
						sc.close();
						System.out.println("프로그램이 종료 되었습니다.");
						System.exit(0);
						break;
					default :
						System.out.println("예약, 조회, 취소, 끝내기 중 선택하세요.");
				} // switch
			}catch(Exception e){
				System.out.println("숫자를 입력해주세요.");
			}
		} // while
	} // main
	static void getSeatRating(Reserve rs){
		switch(rs.getRating()){
		case 1:
			System.out.print(rs.getsSeat());
			System.out.println();
			break;
		case 2:
			System.out.print(rs.getaSeat());
			System.out.println();
			break;
		case 3:
			System.out.print(rs.getbSeat());
			System.out.println();
			break;
		}
	}
} //class
